package com.qf.zyh.web.controller.admin;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.zyh.common.Const;
import com.qf.zyh.entity.Type;
import com.qf.zyh.entity.User;
import com.qf.zyh.services.admin.Impl.TypeServicesImpl;
import com.qf.zyh.services.admin.TypeServices;
import com.qf.zyh.util.StrUtils;
import com.qf.zyh.web.controller.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/adminType")
public class AdminTypeCont extends BaseServlet {
    private TypeServices ts = new TypeServicesImpl();

    public String getGoodsType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<Type> typeList = ts.seleall();

        request.setAttribute("TypeList", typeList);
        return Const.SysConst.FORWARD + "showGoodsType.jsp";
    }

    public String getTypein(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String tname = request.getParameter("tname");
        String tinfo = request.getParameter("tinfo");

        List<Type> typeList = ts.selein(tname, tinfo);
        request.setAttribute("tname", tname);
        request.setAttribute("tinfo", tinfo);
        request.setAttribute("TypeList", typeList);
        return Const.SysConst.FORWARD + "showGoodsType.jsp";
    }

    public String updaType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer tid = StrUtils.toint(request.getParameter("tid"));
        return null;
    }
    public String delType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer tid = StrUtils.toint(request.getParameter("tid"));
        ts.del(tid);
        return Const.SysConst.REDIRECT+"admin/adminType?method=getGoodsType";
    }
}
